-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
makefiles/suit: store public keys, make it easier to work with multiple keys #20858
Conversation
3f839d4
to
db70fa0
Compare
Cool feature. Maybe this is simply a case of bad usage but was still kind of unexpected to me. |
db70fa0
to
1e49e23
Compare
heh, good catch! We might also just replace that call to the 'custom' Python script with another OpenSSL invocation. |
7b67d77
to
2a18905
Compare
This makes it easier to work with encrypted keys and multiple keys. The firmware binary can contain multiple public keys that are used to verify the manifest. The use case is that we want to include the production public key in the debug build, so we can seamlessly update to the production version without re-flashing the device. If the public keys is always generated on the fly, this would still require the production key password even for the debug build. Instead if we store the (unencrypted) public key, we can always include it in the debug build.
2a18905
to
5c8f6ad
Compare
5c8f6ad
to
99285d3
Compare
a197a0f
to
c40262e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make -C examples/suit_update clean suit/publish SUIT_KEY="default prod" SUIT_KEY_SIGN=prod SUIT_SEC_PASSWORD=123456789
make: Entering directory '/home/fabian.huessler@ml-pa.loc/RIOT/examples/suit_update'
rm -rf /home/fabian.huessler@ml-pa.loc/RIOT/bootloaders/riotboot/bin/samr21-xpro/pkg-build/cmsis
# Reset package to checkout state.
rm -rf /home/fabian.huessler@ml-pa.loc/RIOT/build/pkg/c25519
rm -rf /home/fabian.huessler@ml-pa.loc/RIOT/examples/suit_update/bin/samr21-xpro/pkg-build/cmsis
rm -rf /home/fabian.huessler@ml-pa.loc/RIOT/examples/suit_update/bin/samr21-xpro/pkg-build/libcose
rm -rf /home/fabian.huessler@ml-pa.loc/RIOT/examples/suit_update/bin/samr21-xpro/pkg-build/nanocbor
compiling /home/fabian.huessler@ml-pa.loc/RIOT/dist/tools/riotboot_gen_hdr/bin/genhdr...
make: Nothing to be done for 'all'.
suit: generating key in /home/fabian.huessler@ml-pa.loc/.local/share/RIOT/keys
0) none
1) aes-256-cbc
Choose encryption for key file /home/fabian.huessler@ml-pa.loc/.local/share/RIOT/keys/prod.pem: 1
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
read EC key
Enter pass phrase for /home/fabian.huessler@ml-pa.loc/.local/share/RIOT/keys/prod.pem:
writing EC key
read EC key
writing EC key
read EC key
writing EC key
test "dbfb4285837ab2ea3d99c448b22877cc7a139ccbaebb1de367e2bec1fd562fe629b389d86603915448078b8fd7e631c8fc9a7d126eb889a1ba0c17611369b190 /home/fabian.huessler@ml-pa.loc/RIOT/build/pkg/c25519-2017-10-05.zip" = "$(sha512sum "/home/fabian.huessler@ml-pa.loc/RIOT/build/pkg/c25519-2017-10-05.zip")"
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/pkg/c25519/
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/build/pkg/c25519/src -f /home/fabian.huessler@ml-pa.loc/RIOT/Makefile.base MODULE=c25519
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/pkg/cmsis/
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/pkg/libcose/
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/build/pkg/libcose/src -f /home/fabian.huessler@ml-pa.loc/RIOT/Makefile.base MODULE=libcose
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/build/pkg/libcose/src/crypt -f /home/fabian.huessler@ml-pa.loc/RIOT/pkg/libcose/Makefile.libcose_crypt
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/pkg/nanocbor/
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/build/pkg/nanocbor/src -f /home/fabian.huessler@ml-pa.loc/RIOT/Makefile.base MODULE=nanocbor
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/boards/common/init
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/boards/samr21-xpro
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/core
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/core/lib
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/cpu/samd21
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/cpu/cortexm_common
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/cpu/cortexm_common/periph
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/cpu/sam0_common
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/cpu/sam0_common/periph
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/cpu/samd21/periph
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/cpu/samd21/vectors
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/drivers
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/drivers/edbg_eui
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/drivers/ethos
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/drivers/netdev
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/drivers/periph_common
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/pkg/libcose/init
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/auto_init
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/checksum
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/crypto
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/div
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/event
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/evtimer
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/fmt
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/frac
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/hashes
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/iolist
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/isrpipe
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/libc
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/luid
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/malloc_thread_safe
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/application_layer/nanocoap
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/application_layer/uhcp
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/crosslayer/inet_csum
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/gnrc
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/gnrc/netapi
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/gnrc/netif
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/gnrc/netif/ethernet
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/gnrc/netif/hdr
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/gnrc/netif/init_devs
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/gnrc/netreg
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/gnrc/network_layer/icmpv6
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/gnrc/network_layer/icmpv6/echo
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/gnrc/network_layer/ipv6
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/gnrc/network_layer/ipv6/hdr
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/gnrc/network_layer/ipv6/nib
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/gnrc/network_layer/ndp
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/gnrc/pkt
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/gnrc/pktbuf
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/gnrc/pktbuf_static
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/gnrc/sock
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/gnrc/sock/udp
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/gnrc/transport_layer/udp
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/gnrc/application_layer/uhcpc
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/link_layer/eui_provider
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/link_layer/l2util
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/netif
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/netutils
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/network_layer/icmpv6
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/network_layer/ipv6/addr
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/network_layer/ipv6/hdr
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/sock
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/net/transport_layer/udp
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/newlib_syscalls_default
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/pm_layered
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/posix/inet
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/preprocessor
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/progress_bar
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/random
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/riotboot
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/shell
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/shell/cmds
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/suit
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/suit/storage
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/suit/transport
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/test_utils/interactive_sync
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/tiny_strerror
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/tsrb
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/uuid
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/vfs
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/vfs_util
"make" -C /home/fabian.huessler@ml-pa.loc/RIOT/sys/ztimer
creating /home/fabian.huessler@ml-pa.loc/RIOT/examples/suit_update/bin/samr21-xpro/riotboot_files/slot0.1726166621.bin...
creating /home/fabian.huessler@ml-pa.loc/RIOT/examples/suit_update/bin/samr21-xpro/riotboot_files/slot1.1726166621.bin...
published "/home/fabian.huessler@ml-pa.loc/RIOT/examples/suit_update/bin/samr21-xpro/suit_files/riot.suit.1726166621.bin"
as "coap://localhost/fw/suit_update/samr21-xpro/riot.suit.1726166621.bin"
published "/home/fabian.huessler@ml-pa.loc/RIOT/examples/suit_update/bin/samr21-xpro/suit_files/riot.suit.latest.bin"
as "coap://localhost/fw/suit_update/samr21-xpro/riot.suit.latest.bin"
published "/home/fabian.huessler@ml-pa.loc/RIOT/examples/suit_update/bin/samr21-xpro/riotboot_files/slot0.1726166621.bin"
as "coap://localhost/fw/suit_update/samr21-xpro/slot0.1726166621.bin"
published "/home/fabian.huessler@ml-pa.loc/RIOT/examples/suit_update/bin/samr21-xpro/riotboot_files/slot1.1726166621.bin"
as "coap://localhost/fw/suit_update/samr21-xpro/slot1.1726166621.bin"
make: Leaving directory '/home/fabian.huessler@ml-pa.loc/RIOT/examples/suit_update'
const uint8_t public_key[][32] = {
{
0xad, 0x7f, 0x4e, 0xc2, 0xd5, 0x0b, 0xa3, 0xb3, 0xef, 0x8f, 0x7a, 0xc5,
0xa6, 0x73, 0xcc, 0x4a, 0xf5, 0x01, 0x30, 0xae, 0x6a, 0x58, 0xf8, 0xce,
0xd4, 0xcf, 0x8e, 0xf9, 0x3f, 0xc6, 0xc8, 0x92
},
{
0x18, 0xcb, 0x23, 0x9f, 0x6c, 0xd6, 0x82, 0xae, 0x7f, 0xbd, 0x77, 0xc1,
0x4a, 0x9b, 0x04, 0x33, 0xa4, 0xce, 0x99, 0xb6, 0x12, 0x92, 0x38, 0x5b,
0x1d, 0xdf, 0xd4, 0x87, 0x67, 0x2c, 0x4d, 0xed
},
};
Co-authored-by: Fabian Hüßler <fabian.huessler@ml-pa.com>
c40262e
to
765dd68
Compare
Thank you for the review! |
Contribution description
This makes it easier to work with encrypted keys and multiple keys. The firmware binary can contain multiple public keys that are used to verify the manifest.
The use case is that we want to include the production public key in the debug build, so we can seamlessly update to the production version without re-flashing the device.
If the public keys is always generated on the fly, this would still require the production key password even for the debug build.
Instead if we store the (unencrypted) public key, we can always include it in the debug build.
Testing procedure
prod.pem
examples/suit_update
withmake SUIT_KEY="default prod"
OpenSSL only asks for the passwort to create the public key once, then the firmware can be build without needing to decrypt the production key.
contents of generated
riotbuild/public_key.h
Only when the firmware is published (signed) the password for the production key needs to be entered.
Issues/PRs references